
import FormCityApi from "@/api/form/core/formCity";

export default {
    data(){
        return {
            treeData:[],
            expandedKeys:[],
            isLoading:false,
            rootNode:{
                name:"城市管理",
                id:"0",
                areaCode:"0",
                parentId:"-1",
                children:[],
                slots:{icon: 'smile'},
            }
        }
    },
    created() {
        this.init();
    },
    methods:{
        init(){
            this.treeData.push(this.rootNode);
            //默认展开第一个；
            this.expandedKeys.push(this.rootNode.id)

            this.triggerClick(true,this.rootNode,this.treeData);
        },
        async triggerClick(trigger,tree,parenData){
            if(!trigger){
                return
            }
            //如果已经展开
            if(tree.children && tree.children.length > 0){
                return ;
            }

            let res =await FormCityApi.getByParentId(tree.areaCode);
            if(res){
                let _data = [...res];
                tree.children= _data ;
            }
            tree.loading=false;
        }

    }
}